fixed bug causing "discussion" tab to be always a view link, not an edit link
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Template-filler skin base class
19 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
20 * Based on Brion's smarty skin
21 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 *
23 * Todo: Needs some serious refactoring into functions that correspond
24 * to the computations individual esi snippets need. Most importantly no body
25 * parsing for most of those of course.
26 *
27 * PHPTAL support has been moved to a subclass in SkinPHPTal.php,
28 * and is optional. You'll need to install PHPTAL manually to use
29 * skins that depend on it.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42
43 /**
44 * Wrapper object for MediaWiki's localization functions,
45 * to be passed to the template engine.
46 *
47 * @access private
48 * @package MediaWiki
49 */
50 class MediaWiki_I18N {
51 var $_context = array();
52
53 function set($varName, $value) {
54 $this->_context[$varName] = $value;
55 }
56
57 function translate($value) {
58 $fname = 'SkinTemplate-translate';
59 wfProfileIn( $fname );
60
61 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
62 $value = preg_replace( '/^string:/', '', $value );
63
64 $value = wfMsg( $value );
65 // interpolate variables
66 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
67 list($src, $var) = $m;
68 wfSuppressWarnings();
69 $varValue = $this->_context[$var];
70 wfRestoreWarnings();
71 $value = str_replace($src, $varValue, $value);
72 }
73 wfProfileOut( $fname );
74 return $value;
75 }
76 }
77
78 /**
79 *
80 * @package MediaWiki
81 */
82 class SkinTemplate extends Skin {
83 /**#@+
84 * @access private
85 */
86
87 /**
88 * Name of our skin, set in initPage()
89 * It probably need to be all lower case.
90 */
91 var $skinname;
92
93 /**
94 * Stylesheets set to use
95 * Sub directory in ./skins/ where various stylesheets are located
96 */
97 var $stylename;
98
99 /**
100 * For QuickTemplate, the name of the subclass which
101 * will actually fill the template.
102 *
103 * In PHPTal mode, name of PHPTal template to be used.
104 * '.pt' will be automaticly added to it on PHPTAL object creation
105 */
106 var $template;
107
108 /**#@-*/
109
110 /**
111 * Setup the base parameters...
112 * Child classes should override this to set the name,
113 * style subdirectory, and template filler callback.
114 *
115 * @param OutputPage $out
116 */
117 function initPage( &$out ) {
118 parent::initPage( $out );
119 $this->skinname = 'monobook';
120 $this->stylename = 'monobook';
121 $this->template = 'QuickTemplate';
122 }
123
124 /**
125 * Create the template engine object; we feed it a bunch of data
126 * and eventually it spits out some HTML. Should have interface
127 * roughly equivalent to PHPTAL 0.7.
128 *
129 * @param string $callback (or file)
130 * @param string $repository subdirectory where we keep template files
131 * @param string $cache_dir
132 * @return object
133 * @access private
134 */
135 function &setupTemplate( $classname, $repository=false, $cache_dir=false ) {
136 return new $classname();
137 }
138
139 /**
140 * initialize various variables and generate the template
141 *
142 * @param OutputPage $out
143 * @access public
144 */
145 function outputPage( &$out ) {
146 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
147 global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode, $wgUseNewInterlanguage;
148 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgUseDatabaseMessages, $wgRequest;
149 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
150 global $wgMaxCredits, $wgShowCreditsIfMax;
151 global $wgPageShowWatchingUsers;
152
153 $fname = 'SkinTemplate::outputPage';
154 wfProfileIn( $fname );
155
156 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
157
158 wfProfileIn( "$fname-init" );
159 $this->initPage( $out );
160
161 $this->mTitle =& $wgTitle;
162 $this->mUser =& $wgUser;
163
164 $tpl =& $this->setupTemplate( $this->template, 'skins' );
165
166 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
167 $tpl->setTranslator(new MediaWiki_I18N());
168 #}
169 wfProfileOut( "$fname-init" );
170
171 wfProfileIn( "$fname-stuff" );
172 $this->thispage = $this->mTitle->getPrefixedDbKey();
173 $this->thisurl = $this->mTitle->getPrefixedURL();
174 $this->loggedin = $wgUser->isLoggedIn();
175 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
176 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
177 $this->username = $wgUser->getName();
178 $userPage = $wgUser->getUserPage();
179 $this->userpage = $userPage->getPrefixedText();
180 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
181
182 $this->usercss = $this->userjs = $this->userjsprev = false;
183 $this->setupUserCss();
184 $this->setupUserJs();
185 $this->titletxt = $this->mTitle->getPrefixedText();
186 wfProfileOut( "$fname-stuff" );
187
188 wfProfileIn( "$fname-stuff2" );
189 $tpl->set( 'title', $wgOut->getPageTitle() );
190 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
191
192 $tpl->setRef( "thispage", $this->thispage );
193 $subpagestr = $this->subPageSubtitle();
194 $tpl->set(
195 'subtitle', !empty($subpagestr)?
196 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
197 $out->getSubtitle()
198 );
199 $undelete = $this->getUndeleteLink();
200 $tpl->set(
201 "undelete", !empty($undelete)?
202 '<span class="subpages">'.$undelete.'</span>':
203 ''
204 );
205
206 $tpl->set( 'catlinks', $this->getCategories());
207 if( $wgOut->isSyndicated() ) {
208 $feeds = array();
209 foreach( $wgFeedClasses as $format => $class ) {
210 $feeds[$format] = array(
211 'text' => $format,
212 'href' => $wgRequest->appendQuery( "feed=$format" ),
213 'ttip' => wfMsg('tooltip-'.$format)
214 );
215 }
216 $tpl->setRef( 'feeds', $feeds );
217 } else {
218 $tpl->set( 'feeds', false );
219 }
220 $tpl->setRef( 'mimetype', $wgMimeType );
221 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
222 $tpl->setRef( 'charset', $wgOutputEncoding );
223 $tpl->set( 'headlinks', $out->getHeadLinks() );
224 $tpl->setRef( 'wgScript', $wgScript );
225 $tpl->setRef( 'skinname', $this->skinname );
226 $tpl->setRef( 'stylename', $this->stylename );
227 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
228 $tpl->setRef( 'loggedin', $this->loggedin );
229 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
230 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
231 /* XXX currently unused, might get useful later
232 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
233 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
234 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
235 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
236 $tpl->set( "helppage", wfMsg('helppage'));
237 */
238 $tpl->set( 'searchaction', $this->escapeSearchLink() );
239 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
240 $tpl->setRef( 'stylepath', $wgStylePath );
241 $tpl->setRef( 'logopath', $wgLogo );
242 $tpl->setRef( "lang", $wgContLanguageCode );
243 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
244 $tpl->set( 'rtl', $wgContLang->isRTL() );
245 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
246 $tpl->setRef( 'username', $this->username );
247 $tpl->setRef( 'userpage', $this->userpage);
248 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
249 $tpl->setRef( 'usercss', $this->usercss);
250 $tpl->setRef( 'userjs', $this->userjs);
251 $tpl->setRef( 'userjsprev', $this->userjsprev);
252 global $wgUseSiteJs;
253 if ($wgUseSiteJs) {
254 if($this->loggedin) {
255 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
256 } else {
257 $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
258 }
259 } else {
260 $tpl->set('jsvarurl', false);
261 }
262 if( $wgUser->getNewtalk() ) {
263 $usertitle = $this->mUser->getUserPage();
264 $usertalktitle = $usertitle->getTalkPage();
265 if( !$usertalktitle->equals( $this->mTitle ) ) {
266 $ntl = wfMsg( 'newmessages',
267 $this->makeKnownLinkObj(
268 $usertalktitle,
269 wfMsg('newmessageslink')
270 )
271 );
272 # Disable Cache
273 $wgOut->setSquidMaxage(0);
274 }
275 } else {
276 $ntl = '';
277 }
278 wfProfileOut( "$fname-stuff2" );
279
280 wfProfileIn( "$fname-stuff3" );
281 $tpl->setRef( 'newtalk', $ntl );
282 $tpl->setRef( 'skin', $this);
283 $tpl->set( 'logo', $this->logoText() );
284 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
285 if ( !$wgDisableCounters ) {
286 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
287 if ( $viewcount ) {
288 $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
289 } else {
290 $tpl->set('viewcount', false);
291 }
292 } else {
293 $tpl->set('viewcount', false);
294 }
295
296 if ($wgPageShowWatchingUsers) {
297 $dbr =& wfGetDB( DB_SLAVE );
298 extract( $dbr->tableNames( 'watchlist' ) );
299 $sql = "SELECT COUNT(*) AS n FROM $watchlist
300 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBKey()) .
301 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
302 $res = $dbr->query( $sql, 'SkinPHPTal::outputPage');
303 $x = $dbr->fetchObject( $res );
304 $numberofwatchingusers = $x->n;
305 if ($numberofwatchingusers > 0) {
306 $tpl->set('numberofwatchingusers', wfMsg('number_of_watching_users_pageview', $numberofwatchingusers));
307 } else {
308 $tpl->set('numberofwatchingusers', false);
309 }
310 } else {
311 $tpl->set('numberofwatchingusers', false);
312 }
313
314 $tpl->set('copyright',$this->getCopyright());
315
316 $this->credits = false;
317
318 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
319 require_once("Credits.php");
320 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
321 } else {
322 $tpl->set('lastmod', $this->lastModified());
323 }
324
325 $tpl->setRef( 'credits', $this->credits );
326
327 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
328 $tpl->set('copyright', $this->getCopyright());
329 $tpl->set('viewcount', false);
330 $tpl->set('lastmod', false);
331 $tpl->set('credits', false);
332 $tpl->set('numberofwatchingusers', false);
333 } else {
334 $tpl->set('copyright', false);
335 $tpl->set('viewcount', false);
336 $tpl->set('lastmod', false);
337 $tpl->set('credits', false);
338 $tpl->set('numberofwatchingusers', false);
339 }
340 wfProfileOut( "$fname-stuff3" );
341
342 wfProfileIn( "$fname-stuff4" );
343 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
344 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
345 $tpl->set( 'disclaimer', $this->disclaimerLink() );
346 $tpl->set( 'about', $this->aboutLink() );
347
348 $tpl->setRef( 'debug', $out->mDebugtext );
349 $tpl->set( 'reporttime', $out->reportTime() );
350 $tpl->set( 'sitenotice', wfGetSiteNotice() );
351
352 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
353 $out->mBodytext .= $printfooter ;
354 $tpl->setRef( 'bodytext', $out->mBodytext );
355
356 # Language links
357 $language_urls = array();
358
359 if ( !$wgHideInterlanguageLinks ) {
360 foreach( $wgOut->getLanguageLinks() as $l ) {
361 $nt = Title::newFromText( $l );
362 $language_urls[] = array('href' => $nt->getFullURL(),
363 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
364 'class' => $wgContLang->isRTL() ? 'rtl' : 'ltr');
365 }
366 }
367 if(count($language_urls)) {
368 $tpl->setRef( 'language_urls', $language_urls);
369 } else {
370 $tpl->set('language_urls', false);
371 }
372 wfProfileOut( "$fname-stuff4" );
373
374 # Personal toolbar
375 $tpl->set('personal_urls', $this->buildPersonalUrls());
376 $content_actions = $this->buildContentActionUrls();
377 $tpl->setRef('content_actions', $content_actions);
378
379 // XXX: attach this from javascript, same with section editing
380 if($this->iseditable && $wgUser->getOption("editondblclick") )
381 {
382 $tpl->set('body_ondblclick', 'document.location = "' .$content_actions['edit']['href'] .'";');
383 } else {
384 $tpl->set('body_ondblclick', false);
385 }
386 if( $this->iseditable && $wgUser->getOption( 'editsectiononrightclick' ) ) {
387 $tpl->set( 'body_onload', 'setupRightClickEdit()' );
388 } else {
389 $tpl->set( 'body_onload', false );
390 }
391 $tpl->set( 'sidebar', $this->buildSidebar() );
392 $tpl->set( 'nav_urls', $this->buildNavUrls() );
393
394 // execute template
395 wfProfileIn( "$fname-execute" );
396 $res = $tpl->execute();
397 wfProfileOut( "$fname-execute" );
398
399 // result may be an error
400 $this->printOrError( $res );
401 wfProfileOut( $fname );
402 }
403
404 /**
405 * Output the string, or print error message if it's
406 * an error object of the appropriate type.
407 * For the base class, assume strings all around.
408 *
409 * @param mixed $str
410 * @access private
411 */
412 function printOrError( &$str ) {
413 echo $str;
414 }
415
416 /**
417 * build array of urls for personal toolbar
418 * @return array
419 * @access private
420 */
421 function buildPersonalUrls() {
422 $fname = 'SkinTemplate::buildPersonalUrls';
423 wfProfileIn( $fname );
424
425 /* set up the default links for the personal toolbar */
426 global $wgShowIPinHeader;
427 $personal_urls = array();
428 if ($this->loggedin) {
429 $personal_urls['userpage'] = array(
430 'text' => $this->username,
431 'href' => &$this->userpageUrlDetails['href'],
432 'class' => $this->userpageUrlDetails['exists']?false:'new'
433 );
434 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
435 $personal_urls['mytalk'] = array(
436 'text' => wfMsg('mytalk'),
437 'href' => &$usertalkUrlDetails['href'],
438 'class' => $usertalkUrlDetails['exists']?false:'new'
439 );
440 $personal_urls['preferences'] = array(
441 'text' => wfMsg('preferences'),
442 'href' => $this->makeSpecialUrl('Preferences')
443 );
444 $personal_urls['watchlist'] = array(
445 'text' => wfMsg('watchlist'),
446 'href' => $this->makeSpecialUrl('Watchlist')
447 );
448 $personal_urls['mycontris'] = array(
449 'text' => wfMsg('mycontris'),
450 'href' => $this->makeSpecialUrl("Contributions/$this->username")
451 );
452 $personal_urls['logout'] = array(
453 'text' => wfMsg('userlogout'),
454 'href' => $this->makeSpecialUrl('Userlogout','returnto=' . $this->thisurl )
455 );
456 } else {
457 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get("session.name")] ) ) {
458 $personal_urls['anonuserpage'] = array(
459 'text' => $this->username,
460 'href' => &$this->userpageUrlDetails['href'],
461 'class' => $this->userpageUrlDetails['exists']?false:'new'
462 );
463 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
464 $personal_urls['anontalk'] = array(
465 'text' => wfMsg('anontalk'),
466 'href' => &$usertalkUrlDetails['href'],
467 'class' => $usertalkUrlDetails['exists']?false:'new'
468 );
469 $personal_urls['anonlogin'] = array(
470 'text' => wfMsg('userlogin'),
471 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
472 );
473 } else {
474
475 $personal_urls['login'] = array(
476 'text' => wfMsg('userlogin'),
477 'href' => $this->makeSpecialUrl('Userlogin', 'returnto=' . $this->thisurl )
478 );
479 }
480 }
481 wfProfileOut( $fname );
482 return $personal_urls;
483 }
484
485
486 function tabAction( &$title, $message, $selected, $query='', $checkEdit=false ) {
487 $classes = array();
488 if( $selected ) {
489 $classes[] = 'selected';
490 }
491 if( $checkEdit && $title->getArticleId() == 0 ) {
492 $classes[] = 'new';
493 $query = 'action=edit';
494 }
495 return array(
496 'class' => implode( ' ', $classes ),
497 'text' => wfMsg( $message ),
498 'href' => $title->getLocalUrl( $query ) );
499 }
500
501 function makeTalkUrlDetails( $name, $urlaction='' ) {
502 $title = Title::newFromText( $name );
503 $title = $title->getTalkPage();
504 $this->checkTitle($title, $name);
505 return array(
506 'href' => $title->getLocalURL( $urlaction ),
507 'exists' => $title->getArticleID() != 0?true:false
508 );
509 }
510
511 function makeArticleUrlDetails( $name, $urlaction='' ) {
512 $title = Title::newFromText( $name );
513 $title= $title->getSubjectPage();
514 $this->checkTitle($title, $name);
515 return array(
516 'href' => $title->getLocalURL( $urlaction ),
517 'exists' => $title->getArticleID() != 0?true:false
518 );
519 }
520
521 /**
522 * an array of edit links by default used for the tabs
523 * @return array
524 * @access private
525 */
526 function buildContentActionUrls () {
527 global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons;
528 $fname = 'SkinTemplate::buildContentActionUrls';
529 wfProfileIn( $fname );
530
531 global $wgUser, $wgRequest;
532 $action = $wgRequest->getText( 'action' );
533 $section = $wgRequest->getText( 'section' );
534 $oldid = $wgRequest->getVal( 'oldid' );
535 $diff = $wgRequest->getVal( 'diff' );
536 $content_actions = array();
537
538 if( $this->iscontent ) {
539
540 $nskey = $this->getNameSpaceKey();
541 $content_actions[$nskey] = $this->tabAction(
542 $this->mTitle->getSubjectPage(),
543 $nskey,
544 !$this->mTitle->isTalkPage() );
545
546 $content_actions['talk'] = $this->tabAction(
547 $this->mTitle->getTalkPage(),
548 'talk',
549 $this->mTitle->isTalkPage(),
550 '',
551 true);
552
553 wfProfileIn( "$fname-edit" );
554 if ( $this->mTitle->userCanEdit() ) {
555 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : false;
556 $istalk = $this->mTitle->isTalkPage();
557 $istalkclass = $istalk?' istalk':'';
558 $content_actions['edit'] = array(
559 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
560 'text' => wfMsg('edit'),
561 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
562 );
563
564 if ( $istalk ) {
565 $content_actions['addsection'] = array(
566 'class' => $section == 'new'?'selected':false,
567 'text' => wfMsg('addsection'),
568 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
569 );
570 }
571 } else {
572 $oid = ( $oldid && ! isset( $diff ) ) ? '&oldid='.IntVal( $oldid ) : '';
573 $content_actions['viewsource'] = array(
574 'class' => ($action == 'edit') ? 'selected' : false,
575 'text' => wfMsg('viewsource'),
576 'href' => $this->mTitle->getLocalUrl( 'action=edit'.$oid )
577 );
578 }
579 wfProfileOut( "$fname-edit" );
580
581 wfProfileIn( "$fname-live" );
582 if ( $this->mTitle->getArticleId() ) {
583
584 $content_actions['history'] = array(
585 'class' => ($action == 'history') ? 'selected' : false,
586 'text' => wfMsg('history_short'),
587 'href' => $this->mTitle->getLocalUrl( 'action=history')
588 );
589
590 if($wgUser->isAllowed('protect')){
591 if(!$this->mTitle->isProtected()){
592 $content_actions['protect'] = array(
593 'class' => ($action == 'protect') ? 'selected' : false,
594 'text' => wfMsg('protect'),
595 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
596 );
597
598 } else {
599 $content_actions['unprotect'] = array(
600 'class' => ($action == 'unprotect') ? 'selected' : false,
601 'text' => wfMsg('unprotect'),
602 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
603 );
604 }
605 }
606 if($wgUser->isAllowed('delete')){
607 $content_actions['delete'] = array(
608 'class' => ($action == 'delete') ? 'selected' : false,
609 'text' => wfMsg('delete'),
610 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
611 );
612 }
613 if ( $wgUser->isLoggedIn() ) {
614 if ( $this->mTitle->userCanMove()) {
615 $content_actions['move'] = array(
616 'class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false,
617 'text' => wfMsg('move'),
618 'href' => $this->makeSpecialUrl("Movepage/$this->thispage" )
619 );
620 }
621 }
622 } else {
623 //article doesn't exist or is deleted
624 if($wgUser->isAllowed('delete')){
625 if( $n = $this->mTitle->isDeleted() ) {
626 $content_actions['undelete'] = array(
627 'class' => false,
628 'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
629 'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
630 );
631 }
632 }
633 }
634 wfProfileOut( "$fname-live" );
635
636 if( $wgUser->isLoggedIn() and $action != 'submit' ) {
637 if( !$this->mTitle->userIsWatching()) {
638 $content_actions['watch'] = array(
639 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
640 'text' => wfMsg('watch'),
641 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
642 );
643 } else {
644 $content_actions['unwatch'] = array(
645 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
646 'text' => wfMsg('unwatch'),
647 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
648 );
649 }
650 }
651
652 if( $wgUser->isLoggedIn() || $wgValidationForAnons ) { # and $action != 'submit' ) {
653 # Validate tab. TODO: add validation to logged-in user rights
654 if($wgUseValidation && ( $action == "" || $action=='view' ) ){ # && $wgUser->isAllowed('validate')){
655 if ( $oldid ) $oid = IntVal( $oldid ) ; # Use the oldid
656 else
657 {# Trying to get the current article revision through this weird stunt
658 $tid = $this->mTitle->getArticleID();
659 $tns = $this->mTitle->getNamespace();
660 $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}" ;
661 $res = wfQuery( $sql, DB_READ );
662 if( $s = wfFetchObject( $res ) )
663 $oid = $s->page_latest ;
664 else $oid = "" ; # Something's wrong, like the article has been deleted in the last 10 ns
665 }
666 if ( $oid != "" ) {
667 $oid = "&revision={$oid}" ;
668 $content_actions['validate'] = array(
669 'class' => ($action == 'validate') ? 'selected' : false,
670 'text' => wfMsg('val_tab'),
671 'href' => $this->mTitle->getLocalUrl( "action=validate{$oid}" )
672 );
673 }
674 }
675 }
676 } else {
677 /* show special page tab */
678
679 $content_actions['article'] = array(
680 'class' => 'selected',
681 'text' => wfMsg('specialpage'),
682 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
683 );
684 }
685
686 /* show links to different language variants */
687 global $wgDisableLangConversion;
688 $variants = $wgContLang->getVariants();
689 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
690 $preferred = $wgContLang->getPreferredVariant();
691 $actstr = '';
692 if( $action )
693 $actstr = 'action=' . $action . '&';
694 $vcount=0;
695 foreach( $variants as $code ) {
696 $varname = $wgContLang->getVariantname( $code );
697 if( $varname == 'disable' )
698 continue;
699 $selected = ( $code == $preferred )? 'selected' : false;
700 $content_actions['varlang-' . $vcount] = array(
701 'class' => $selected,
702 'text' => $varname,
703 'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
704 );
705 $vcount ++;
706 }
707 }
708
709 // A print stylesheet is attached to all pages, but nobody ever
710 // figures that out. :) Add a link...
711 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
712 $content_actions['print'] = array(
713 'class' => false,
714 'text' => wfMsg( 'print' ),
715 'href' => $wgRequest->appendQuery( 'printable=yes' ) );
716 }
717
718 wfProfileOut( $fname );
719 return $content_actions;
720 }
721
722 /**
723 * Build an array that represents the sidebar(s), the navigation bar among them
724 *
725 * @return array
726 * @access private
727 */
728 function buildSidebar() {
729 $fname = 'SkinTemplate::buildSidebar';
730 wfProfileIn( $fname );
731
732 $bar = array();
733 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
734 foreach ($lines as $line) {
735 if (strpos($line, '*') !== 0)
736 continue;
737 if (strpos($line, '**') !== 0) {
738 $line = trim($line, '* ');
739 $heading = $line;
740 } else {
741 if (strpos($line, '|') !== false) { // sanity check
742 $line = explode( '|' , trim($line, '* '), 2 );
743 $link = wfMsgForContent( $line[0] );
744 if( $link == '-' ) {
745 continue;
746 }
747 $bar[$heading][] = array(
748 'text' => wfMsg( $line[1] ),
749 'href' => $this->makeInternalOrExternalUrl( $link ),
750 'id' => 'n-' . $line[1],
751 );
752 } else { continue; }
753 }
754 }
755
756 wfProfileOut( $fname );
757 return $bar;
758 }
759
760 /**
761 * build array of common navigation links
762 * @return array
763 * @access private
764 */
765 function buildNavUrls () {
766 $fname = 'SkinTemplate::buildNavUrls';
767 wfProfileIn( $fname );
768
769 global $wgUser, $wgRequest;
770 global $wgSiteSupportPage, $wgEnableUploads, $wgUploadNavigationUrl;
771
772 $action = $wgRequest->getText( 'action' );
773 $oldid = $wgRequest->getVal( 'oldid' );
774 $diff = $wgRequest->getVal( 'diff' );
775
776 $nav_urls = array();
777 $nav_urls['mainpage'] = array('href' => $this->makeI18nUrl('mainpage'));
778 $nav_urls['randompage'] = array('href' => $this->makeSpecialUrl('Random'));
779 $nav_urls['recentchanges'] = array('href' => $this->makeSpecialUrl('Recentchanges'));
780 $nav_urls['currentevents'] = (wfMsgForContent('currentevents') != '-') ? array('href' => $this->makeI18nUrl('currentevents')) : false;
781 $nav_urls['portal'] = (wfMsgForContent('portal') != '-') ? array('href' => $this->makeI18nUrl('portal-url')) : false;
782 $nav_urls['bugreports'] = array('href' => $this->makeI18nUrl('bugreportspage'));
783 // $nav_urls['sitesupport'] = array('href' => $this->makeI18nUrl('sitesupportpage'));
784 $nav_urls['sitesupport'] = array('href' => $wgSiteSupportPage);
785 $nav_urls['help'] = array('href' => $this->makeI18nUrl('helppage'));
786 if( $wgEnableUploads ) {
787 if ($wgUploadNavigationUrl) {
788 $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl );
789 } else {
790 $nav_urls['upload'] = array('href' => $this->makeSpecialUrl('Upload'));
791 }
792 } else {
793 $nav_urls['upload'] = false;
794 }
795 $nav_urls['specialpages'] = array('href' => $this->makeSpecialUrl('Specialpages'));
796
797 if( $this->mTitle->getNamespace() != NS_SPECIAL) {
798 $nav_urls['whatlinkshere'] = array(
799 'href' => $this->makeSpecialUrl("Whatlinkshere/$this->thispage")
800 );
801 $nav_urls['recentchangeslinked'] = array(
802 'href' => $this->makeSpecialUrl("Recentchangeslinked/$this->thispage")
803 );
804 }
805
806 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
807 $id = User::idFromName($this->mTitle->getText());
808 $ip = User::isIP($this->mTitle->getText());
809 } else {
810 $id = 0;
811 $ip = false;
812 }
813
814 if($id || $ip) { # both anons and non-anons have contri list
815 $nav_urls['contributions'] = array(
816 'href' => $this->makeSpecialUrl('Contributions/' . $this->mTitle->getText() )
817 );
818 } else {
819 $nav_urls['contributions'] = false;
820 }
821 $nav_urls['emailuser'] = false;
822 if( $this->showEmailUser( $id ) ) {
823 $nav_urls['emailuser'] = array(
824 'href' => $this->makeSpecialUrl('Emailuser/' . $this->mTitle->getText() )
825 );
826 }
827 wfProfileOut( $fname );
828 return $nav_urls;
829 }
830
831 /**
832 * Generate strings used for xml 'id' names
833 * @return string
834 * @private
835 */
836 function getNameSpaceKey () {
837 switch ($this->mTitle->getNamespace()) {
838 case NS_MAIN:
839 case NS_TALK:
840 return 'nstab-main';
841 case NS_USER:
842 case NS_USER_TALK:
843 return 'nstab-user';
844 case NS_MEDIA:
845 return 'nstab-media';
846 case NS_SPECIAL:
847 return 'nstab-special';
848 case NS_PROJECT:
849 case NS_PROJECT_TALK:
850 return 'nstab-wp';
851 case NS_IMAGE:
852 case NS_IMAGE_TALK:
853 return 'nstab-image';
854 case NS_MEDIAWIKI:
855 case NS_MEDIAWIKI_TALK:
856 return 'nstab-mediawiki';
857 case NS_TEMPLATE:
858 case NS_TEMPLATE_TALK:
859 return 'nstab-template';
860 case NS_HELP:
861 case NS_HELP_TALK:
862 return 'nstab-help';
863 case NS_CATEGORY:
864 case NS_CATEGORY_TALK:
865 return 'nstab-category';
866 default:
867 return 'nstab-main';
868 }
869 }
870
871 /**
872 * @access private
873 */
874 function setupUserCss() {
875 $fname = 'SkinTemplate::setupUserCss';
876 wfProfileIn( $fname );
877
878 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
879
880 $sitecss = '';
881 $usercss = '';
882 $siteargs = '&maxage=' . $wgSquidMaxage;
883
884 # Add user-specific code if this is a user and we allow that kind of thing
885
886 if ( $wgAllowUserCss && $this->loggedin ) {
887 $action = $wgRequest->getText('action');
888
889 # if we're previewing the CSS page, use it
890 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
891 $siteargs = "&smaxage=0&maxage=0";
892 $usercss = $wgRequest->getText('wpTextbox1');
893 } else {
894 $usercss = '@import "' .
895 $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
896 'action=raw&ctype=text/css') . '";' ."\n";
897 }
898
899 $siteargs .= '&ts=' . $wgUser->mTouched;
900 }
901
902 if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n";
903
904 # If we use the site's dynamic CSS, throw that in, too
905 if ( $wgUseSiteCss ) {
906 $sitecss .= '@import "' . $this->makeNSUrl(ucfirst($this->skinname) . '.css', 'action=raw&ctype=text/css&smaxage=' . $wgSquidMaxage, NS_MEDIAWIKI) . '";' . "\n";
907 $sitecss .= '@import "' . $this->makeUrl('-','action=raw&gen=css' . $siteargs) . '";' . "\n";
908 }
909
910 # If we use any dynamic CSS, make a little CDATA block out of it.
911
912 if ( !empty($sitecss) || !empty($usercss) ) {
913 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
914 }
915 wfProfileOut( $fname );
916 }
917
918 /**
919 * @access private
920 */
921 function setupUserJs() {
922 $fname = 'SkinTemplate::setupUserJs';
923 wfProfileIn( $fname );
924
925 global $wgRequest, $wgAllowUserJs, $wgJsMimeType;
926 $action = $wgRequest->getText('action');
927
928 if( $wgAllowUserJs && $this->loggedin ) {
929 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
930 # XXX: additional security check/prompt?
931 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
932 } else {
933 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType.'&dontcountme=s');
934 }
935 }
936 wfProfileOut( $fname );
937 }
938
939 /**
940 * returns css with user-specific options
941 * @access public
942 */
943
944 function getUserStylesheet() {
945 $fname = 'SkinTemplate::getUserStylesheet';
946 wfProfileIn( $fname );
947
948 global $wgUser;
949 $s = "/* generated user stylesheet */\n";
950 $s .= $this->reallyDoGetUserStyles();
951 wfProfileOut( $fname );
952 return $s;
953 }
954
955 /**
956 * @access public
957 */
958 function getUserJs() {
959 $fname = 'SkinTemplate::getUserJs';
960 wfProfileIn( $fname );
961
962 global $wgStylePath;
963 $s = '/* generated javascript */';
964 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
965 $s .= '/* MediaWiki:'.ucfirst($this->skinname)." */\n";
966
967 // avoid inclusion of non defined user JavaScript (with custom skins only)
968 // by checking for default message content
969 $msgKey = ucfirst($this->skinname).'.js';
970 $userJS = wfMsg($msgKey);
971 if ('&lt;'.$msgKey.'&gt;' != $userJS) {
972 $s .= $userJS;
973 }
974
975 wfProfileOut( $fname );
976 return $s;
977 }
978 }
979
980 /**
981 * Generic wrapper for template functions, with interface
982 * compatible with what we use of PHPTAL 0.7.
983 * @package MediaWiki
984 * @subpackage Skins
985 */
986 class QuickTemplate {
987 /**
988 * @access public
989 */
990 function QuickTemplate() {
991 $this->data = array();
992 $this->translator = new MediaWiki_I18N();
993 }
994
995 /**
996 * @access public
997 */
998 function set( $name, $value ) {
999 $this->data[$name] = $value;
1000 }
1001
1002 /**
1003 * @access public
1004 */
1005 function setRef($name, &$value) {
1006 $this->data[$name] =& $value;
1007 }
1008
1009 /**
1010 * @access public
1011 */
1012 function setTranslator( &$t ) {
1013 $this->translator = &$t;
1014 }
1015
1016 /**
1017 * @access public
1018 */
1019 function execute() {
1020 echo "Override this function.";
1021 }
1022
1023
1024 /**
1025 * @access private
1026 */
1027 function text( $str ) {
1028 echo htmlspecialchars( $this->data[$str] );
1029 }
1030
1031 /**
1032 * @access private
1033 */
1034 function html( $str ) {
1035 echo $this->data[$str];
1036 }
1037
1038 /**
1039 * @access private
1040 */
1041 function msg( $str ) {
1042 echo htmlspecialchars( $this->translator->translate( $str ) );
1043 }
1044
1045 /**
1046 * @access private
1047 */
1048 function msgHtml( $str ) {
1049 echo $this->translator->translate( $str );
1050 }
1051
1052 /**
1053 * An ugly, ugly hack.
1054 * @access private
1055 */
1056 function msgWiki( $str ) {
1057 global $wgParser, $wgTitle, $wgOut, $wgUseTidy;
1058
1059 $text = $this->translator->translate( $str );
1060 $parserOutput = $wgParser->parse( $text, $wgTitle,
1061 $wgOut->mParserOptions, true );
1062 echo $parserOutput->getText();
1063 }
1064
1065 /**
1066 * @access private
1067 */
1068 function haveData( $str ) {
1069 return $this->data[$str];
1070 }
1071
1072 /**
1073 * @access private
1074 */
1075 function haveMsg( $str ) {
1076 $msg = $this->translator->translate( $str );
1077 return ($msg != '-') && ($msg != ''); # ????
1078 }
1079 }
1080
1081 } // end of if( defined( 'MEDIAWIKI' ) )
1082 ?>